package com.cjk.console.ctrl;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cjk.console.SessionApi;
import com.cjk.console.request.DeviceRequest;
import com.cjk.console.service.TunnelService;
import com.cjk.foundation.commons.response.PageResponse;
import com.cjk.foundation.commons.response.Response;

@Controller
@RequestMapping("/tunnel")
public class TunnelController {
	
	@Autowired
	private TunnelService tunnelService;

	@ResponseBody
	@RequestMapping(value = "/createTunnel.do", method = RequestMethod.POST)
	public Response createTunnel(@RequestBody DeviceRequest request, HttpSession session) {
		final Integer userId = SessionApi.getLoginUserId(session);
		return tunnelService.createTunnel(request, userId);
	}
	
	@ResponseBody
	@RequestMapping(value = "/destoryTunnel.do", method = RequestMethod.POST)
	public Response destoryTunnel(@RequestBody DeviceRequest request, HttpSession session) {
		return tunnelService.destoryTunnel(request.getTunnelId());
	}
	
	@ResponseBody
	@RequestMapping(value = "/getTunnelList.do", method = RequestMethod.POST)
	public PageResponse getTunnelList(@RequestBody DeviceRequest request, HttpSession session) {
		return tunnelService.getTunnelList(request);
	}
	
	@ResponseBody
	@RequestMapping(value = "/getTunnelStatus.do", method = RequestMethod.POST)
	public Response getTunnelStatus(Integer id) {
		return tunnelService.getTunnelStatus(id);
	}
	
}
